// JavaScript Document
var js_debug = true;
/*********************
	loadme - will execute first when JS is dwl on the browser cache
*********************/
function loadme(def)
{
	var str = '';
	var sometext = (def != '' && def != undefined)?def:"loading page.....";	
	str += '<div id="loadme" style="position:absolute;top:0px;left:0px;right:5px;background-color:#FFFF84;width:185px;height:22px;z-index:500; display:block;font-family: Lucida Grande, Verdana, Sans-serif;">';
	str += '<div align="center" style="padding:3px;width:100%;color:#444444;font-size:12px;font-weight:bold;">'+sometext+'<\/div>';
	str += '<\/div>';
	
	if(!document.getElementById('loadme'))
		document.write(str);
		
	document.getElementById('loadme').focus();
}

function is_loaded(){
	
	if(document.getElementById('e_footer')){
		document.getElementById('loadme').style.display='none';
	}else{
		loadme();
		setTimeout("is_loaded()",500);
	}
}
is_loaded();//call me always

function select_all(id){
    if(document.getElementById(id)){		
		alert("The highlighted area is successfully selected.");
		document.getElementById(id).focus();
		document.getElementById(id).select();
		return false;
	}
}


function delete_domain(id,domain,formname){
	var r=confirm("[Warning] \n\nAre your sure you want to permenatly delete domain: '"+domain+"'?");
	if (r==true)
  	{
  		var r=confirm("[Warning] \n\nAll the data for domain: '"+domain+"' will be deleted permenatly?");
		if (r==true)
		{
			var frmobj = document.getElementById(formname);
			frmobj.mode.value = 'delete';
			frmobj.domain_id.value = id;
			frmobj.submit();
		}
  	}	
}

function reset_domain(id,domain,formname){
	var r=confirm("[Warning] \n\nAre your sure you want to reset the domain: '"+domain+"'?");
	if (r==true)
  	{
  		var r=confirm("[Warning] \n\nAll the data for domain: '"+domain+"' will be deleted permenatly?");
		if (r==true)
		{
			var frmobj = document.getElementById(formname);
			frmobj.mode.value = 'reset';
			frmobj.domain_id.value = id;
			frmobj.submit();
		}
  	}	
}

function show_hide(id){
	var state = $('#'+id).css("display");
	if('none' == state){
		$('#'+id).css("display","block");
	}else{
		$('#'+id).css("display","none");
	}
}

function handle_redirect(url)
{
	if(url != "")
	{
		var browser_type=navigator.appName
		var browser_version=parseInt(navigator.appVersion)
		if (browser_type=="Netscape"&&browser_version>=4)
		{
			//if NS 4+	
			window.location.replace(url);
		}		
		else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
		{
			//if IE 4+	
			window.location.replace(url);
		}		
		else
		{
			//Default goto page (NOT NS 4+ and NOT IE 4+)	
			window.location=url;	
		}
	}
}


function open_pop_up(url,set_width,set_height)
{
	var height 		= (set_height) ? set_height : 700;
	var width 		= (set_width) ? set_width : 800;
	var win_stats	= "toolbar=no, width="+width+", height="+height+", status=no,scrollbars=yes, resize=yes, menubar=no"
	if (navigator.appName.indexOf("Microsoft")>=0) 
	{
		win_stats+=',left=0,top=0';
	}
	else
	{	
		win_stats+=',screenX=0,screenY=-0';
	}
	var win_opened;
	if(url != "")
	{
		var win_opened = window.open(url,"new_window",win_stats);
		if(win_opened)
		{
			win_opened.focus();
		}else
		{
			win_opened = false;
		}
		
	}
	return win_opened;
}
function is_popup_blocked(url)
{
 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
 var popUpsBlocked;
 if(mine)
 {
    popUpsBlocked = false
	 mine.close()
 }else
 {
    popUpsBlocked = true
 }
}

/* call all necessary functions once the page is loaded */
$(document).ready(function() {
	//all class .tbl add class alt
	$(".tbl tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  	$(".tbl tr:even").addClass("alt");	
	
	//alt styles for summary boxes	
	$(".li_stripes > li").mouseover(function(){$(this).addClass("liover");}).mouseout(function(){$(this).removeClass("liover");});
	$(".li_stripes > li:even").addClass("lialt");	
	
});


/*********************
	Call Ajax - functions
*********************/
//ajax default messages
var ajx_msg 		= "Please wait, processing your request...";
var ajx_err 		= "Sorry, the service your trying to reach is currently not responding.<br\/>Kindly try again later.";
//ajax default settings
var ajx_type		= 'POST';
var ajx_url			= "";
var ajx_formdata	= {};
var ajx_timeout		= 3000;
var ajx_data_type	= "";//json or ''
var ajx_cache		= false;
var ajx_data 		= '';
//ajax default container and settings
var ajx_container 	= '';
var ajx_return 		= false;
var ajx_handle_func	= '';


function call_ajax(url, frm, divid)
{	
	var formValues = "";
	var div_obj = document.getElementById(divid);
	formValues = $('form#'+frm).serializeArray();
	
	jQuery.ajax({
		   type: ajx_type,
		   url: url,
		   data: formValues,
		   beforeSend: function(){
			   div_obj.innerHTML = ajax_message(ajx_msg);
		   },
		   error: function (XMLHttpRequest, textStatus, errorThrown) {			
				if(js_debug == true){
					str += 'XMLHttpRequest : ';
					str += XMLHttpRequest+'<br\/>';
					str += 'textStatus : ';
					str += textStatus+'<br\/>';
					str += 'errorThrown : ';
					str += errorThrown+'<br\/>';				
					div_obj.innerHTML = ajax_message(str);
				}else{
					div_obj.innerHTML = ajax_message(ajx_err);
				}
			},
			success: function(msg){
				div_obj.innerHTML = '';
				div_obj.innerHTML = msg;			   
			},
			complete: function (XMLHttpRequest, textStatus){
				//do something after completion
			}
	});
}


function ajax_message(body_msg)
{
	var info = '';
	
	info += '<div id="loadme" style="position:absolute;top:25%;left:35%;right:5px;background-color:#F6F6F6;width:350px;height:90px;display:block;font-family: Lucida Grande, Verdana, Sans-serif; border:3px solid #EEEEEE; padding: 25px 10px 5px 10px;">';	
	info += '<div align="center" style="padding:3px;width:100%;color:#444444;font-size:12px;font-weight:bold;">';
	info += '<img src="'+site_url+'images/loadingcircle.gif" border="0" alt="loading" />';
	info += '</div>';
	info += '<div align="center" style="padding:3px;width:100%;color:#444444;font-size:12px;font-weight:bold;">'+body_msg+'</div>';
	info +='</div>';		
	
	return info; 
}

function ajxseocrawler()
{
	txturl = $('#txt_url').val();
	if(txturl == '')
	{
		alert("[Error] Please enter a valid url\nExample:www.example.com");
		$('#txt_url').focus();
	}
	else
	{
		url = site_url+'ajx_crawl.php';
		frm = 'frmseocrawl';
		divid = 'dataseocrawl';
		call_ajax(url, frm, divid);
		ajxresetjsset();
	}
	return false;
}
var ajxresetjsset_timeout = 0;
function ajxresetjsset(){
	if(document.getElementById('js_reset_settings')){
		alert("[Information] SEO page request is completed.");
		reloadajxsettings();
		clearTimeout(ajxresetjsset_timeout);
	}
	else{
		ajxresetjsset_timeout = setTimeout("ajxresetjsset()",2000);
	}
}

function reloadajxsettings()
{
	//all class .tbl add class alt
	$(".tbl tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
  	$(".tbl tr:even").addClass("alt");	
	
	//alt styles for summary boxes	
	$(".li_stripes > li").mouseover(function(){$(this).addClass("liover");}).mouseout(function(){$(this).removeClass("liover");});
	$(".li_stripes > li:even").addClass("lialt");	
}

